/**
 * There are code generation
 */
package com.neusoft.lohas.modules.ivm.web.product;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.google.common.collect.Lists;
import com.neusoft.lohas.common.config.Global;
import com.neusoft.lohas.common.persistence.Page;
import com.neusoft.lohas.common.utils.ConvertToHtml;
import com.neusoft.lohas.common.utils.IdGen;
import com.neusoft.lohas.common.utils.StringUtils;
import com.neusoft.lohas.common.utils.excel.ExcelManager;
import com.neusoft.lohas.common.web.BaseController;
import com.neusoft.lohas.modules.ivm.entity.product.Product;
import com.neusoft.lohas.modules.ivm.entity.product.ProductClassify;
import com.neusoft.lohas.modules.ivm.entity.product.ProductMarketDetail;
import com.neusoft.lohas.modules.ivm.entity.product.ProductRelation;
import com.neusoft.lohas.modules.ivm.entity.product.Supplier;
import com.neusoft.lohas.modules.ivm.service.product.ProductMarketDetailService;
import com.neusoft.lohas.modules.ivm.service.product.ProductService;
import com.neusoft.lohas.modules.ivm.utils.MerchantUtils;
import com.neusoft.lohas.modules.ivm.utils.ProductUtils;

/**
 * 商品信息Controller
 * @author Jackie.Liu
 * @version 2014-11-13
 */
@Controller
@RequestMapping(value = "${adminPath}/ivm/product")
public class ProductController extends BaseController {

	@Autowired
	private ProductService productService;
	@Autowired
	private ProductMarketDetailService productMarketDetailService;
	@Autowired
	private ExcelManager excelManager;
	
	@ModelAttribute
	public Product get(@RequestParam(required=false) String id) {
		if (StringUtils.isNotBlank(id)){
			return productService.get(id);
		}else{
			return new Product();
		}
	}
	
	@RequiresPermissions("ivm:product:view")
	@RequestMapping(value = {"list", ""})
	public String list(Product product, 
			@RequestParam(value="searchParam", required=false, defaultValue="") String searchParam,   
			@RequestParam(value="oneClassify", required=false, defaultValue="") String oneClassify,   //一级分类
			@RequestParam(value="twoClassify", required=false, defaultValue="") String twoClassify,   //二级分类
			@RequestParam(value="sortName", required=false, defaultValue="") String sortName,   //排序字段
			@RequestParam(value="orderBy", required=false, defaultValue="") String orderBy,   //排序方式
			@RequestParam(value="type", required=false, defaultValue="0") int type,
			HttpServletRequest request, HttpServletResponse response, Model model) {
		if(StringUtils.isNotBlank(searchParam)){
			try {
				searchParam = java.net.URLDecoder.decode(searchParam,"UTF-8");
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		}
		if (StringUtils.isNotBlank(oneClassify)) {
			product.setClassify(new ProductClassify(oneClassify));
			List<String> classifyIdList = Lists.newArrayList();
			if(StringUtils.isNotBlank(twoClassify)){
				classifyIdList.add(twoClassify);
			}
			product.setClassifyIdList(classifyIdList);
		}else{
			List<String> classifyIdList = Lists.newArrayList();
			if(StringUtils.isNotBlank(twoClassify)){
				classifyIdList.add(twoClassify);
			}
			product.setClassifyIdList(classifyIdList);
		}
		String sort = sortName+"#"+orderBy;
		if(StringUtils.isBlank(sortName)){
			sort = "sort#asc";
		}
		boolean loadMore = true;
		if(StringUtils.isBlank(oneClassify) && StringUtils.isBlank(twoClassify)){
			loadMore = false;
		}
        Page<Product> page = productService.find(new Page<Product>(request, response), product, searchParam, sort, loadMore); 
        model.addAttribute("page", page);
        model.addAttribute("count", page.getCount());
        model.addAttribute("sortName", sortName);
        model.addAttribute("orderBy", orderBy);
        model.addAttribute("type", type);
        model.addAttribute("searchParam", searchParam);
        model.addAttribute("oneClassify", oneClassify);
        model.addAttribute("twoClassify", twoClassify);
		return "modules/ivm/pro/productList";
	}

	@RequiresPermissions("ivm:product:view")
	@RequestMapping(value = "form")
	public String form(Product product,
			//下面的参数主要用于记录列表页面的查询条件，保存时，可以返回到之前的页面
			@RequestParam(value="searchParam", required=false, defaultValue="") String searchParam,   
			@RequestParam(value="oneClassify", required=false, defaultValue="") String oneClassify,   //一级分类
			@RequestParam(value="twoClassify", required=false, defaultValue="") String twoClassify,   //二级分类
			@RequestParam(value="sortName", required=false, defaultValue="") String sortName,   //排序字段
			@RequestParam(value="orderBy", required=false, defaultValue="") String orderBy,   //排序方式
			@RequestParam(value="type", required=false, defaultValue="0") int type,
			Model model) {
		model.addAttribute("product", product);
		model.addAttribute("merchantId", super.merchant.getId());
		model.addAttribute("sortName", sortName);
        model.addAttribute("orderBy", orderBy);
        model.addAttribute("type", type);
        model.addAttribute("searchParam", searchParam);
        model.addAttribute("oneClassify", oneClassify);
        model.addAttribute("twoClassify", twoClassify);
		return "modules/ivm/pro/productForm";
	}

	@RequiresPermissions("ivm:product:edit")
	@RequestMapping(value = "save")
	public String save(Product product, String oldName,
			@RequestParam(value="mobile", required=false, defaultValue="false") Boolean mobile,
			@RequestParam(value="searchParam", required=false, defaultValue="") String searchParam,   
			@RequestParam(value="oneClassify", required=false, defaultValue="") String oneClassify,   //一级分类
			@RequestParam(value="twoClassify", required=false, defaultValue="") String twoClassify,   //二级分类
			@RequestParam(value="sortName", required=false, defaultValue="") String sortName,   //排序字段
			@RequestParam(value="orderBy", required=false, defaultValue="") String orderBy,   //排序方式
			@RequestParam(value="type", required=false, defaultValue="0") int type,
			Model model, RedirectAttributes redirectAttributes) {
		if (StringUtils.isBlank(product.getId())) { //为空，则为新增
			product.setCode(productService.getMaxCode(super.merchant.getId())+1);
		}
		//检查是否有必填项未填写
		if(StringUtils.isBlank(product.getName()) || StringUtils.isBlank(product.getAssisTitle()) || StringUtils.isBlank(product.getOpenState())){
			addMessage(model, "商品信息填写不完整，请检查.");
			return form(product, searchParam, oneClassify, twoClassify, sortName, orderBy, type, model);
		}
		if(product.getProductUnit()==null || product.getSpecUnit()==null || StringUtils.isBlank(product.getToPay()) || StringUtils.isBlank(product.getEffectiveTime())){
			addMessage(model, "销售填写不完整，请检查.");
			return form(product, searchParam, oneClassify, twoClassify, sortName, orderBy, type, model);
		}
		product.setMerchant(super.merchant);
		if (!beanValidator(model, product)){
			return form(product, searchParam, oneClassify, twoClassify, sortName, orderBy, type, model);
		}
		if (!"true".equals(checkName(oldName, product.getName()))){
			addMessage(model, "保存商品'" + product.getName() + "'失败，商品名已存在");
			return form(product, searchParam, oneClassify, twoClassify, sortName, orderBy, type, model);
		}
		// 角色数据有效性验证，过滤不在授权内的角色
		List<ProductClassify> classifyList = Lists.newArrayList();
		List<String> classifyIdList = product.getClassifyIdList();
		for (ProductClassify classify : productService.findAllClassify()){
			if (classifyIdList.contains(classify.getId())){
				classifyList.add(classify);
			}
		}
		product.setClassifyList(classifyList);
		//设置供应商
		List<Supplier> supplierList = Lists.newArrayList();
		List<String> supplierIdList = product.getSupplierIdList();
		for (Supplier supplier : ProductUtils.getSupplierList()){
			if (supplierIdList.contains(supplier.getId())){
				supplierList.add(supplier);
			}
		}
		if(supplierList.size()>0){
			product.setDefaultSupplier(supplierList.get(0));
		}else{
			product.setDefaultSupplier(null);
		}
		product.setSupplierList(supplierList);
		product.setShouldKnow(ConvertToHtml.convertor(product.getShouldKnow()));
		product.setRemarks(ConvertToHtml.convertor(product.getRemarks()));
		//关联信息
		if (product.getRelationList().size()>0) {
			for (ProductRelation relation : product.getRelationList()) {
				if (StringUtils.isBlank(relation.getId())) {
					relation.setParent(product);
					relation.setMerchant(super.merchant);
					relation.setId(IdGen.uuid());
					relation.prePersist();
				}
			}
		}
		productService.save(product);
		addMessage(redirectAttributes, "保存商品信息'" + product.getName() + "'成功");
		if (mobile) {
			return "redirect:"+Global.getAdminPath()+"/ivm/product/";
		}
		//对searchParam编码，避免传入到list出现乱码
		if(StringUtils.isNotBlank(searchParam)){
			try {
				searchParam = java.net.URLEncoder.encode(searchParam,"UTF-8");
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		}
		return "redirect:"+Global.getAdminPath()+"/ivm/product?searchParam="+searchParam+"&oneClassify="+oneClassify+"&twoClassify="+twoClassify
			+"&sortName="+sortName+"&orderBy="+orderBy+"&type="+type;
	}
	
	@RequiresPermissions("ivm:product:edit")
	@RequestMapping(value = "delete")
	public String delete(String id, 
			@RequestParam(value="mobile", required=false, defaultValue="false") Boolean mobile,
			@RequestParam(value="searchParam", required=false, defaultValue="") String searchParam,   
			@RequestParam(value="oneClassify", required=false, defaultValue="") String oneClassify,   //一级分类
			@RequestParam(value="twoClassify", required=false, defaultValue="") String twoClassify,   //二级分类
			@RequestParam(value="sortName", required=false, defaultValue="") String sortName,   //排序字段
			@RequestParam(value="orderBy", required=false, defaultValue="") String orderBy,   //排序方式
			@RequestParam(value="type", required=false, defaultValue="0") int type,
			RedirectAttributes redirectAttributes) {
		productService.delete(id);
		addMessage(redirectAttributes, "删除商品信息成功");
		if(StringUtils.isNotBlank(searchParam)){
			try {
				searchParam = java.net.URLEncoder.encode(searchParam,"UTF-8");
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		}
		return "redirect:"+Global.getAdminPath()+"/ivm/product?searchParam="+searchParam+"&oneClassify="+oneClassify+"&twoClassify="+twoClassify
			+"&sortName="+sortName+"&orderBy="+orderBy+"&type="+type;
	}
	
	@ResponseBody
	@RequiresPermissions("sys:product:edit")
	@RequestMapping(value = "checkName")
	public String checkName(String oldName, String name) {
		if (name !=null && name.equals(oldName)) {
			return "true";
		} else if (name !=null && productService.getProductByName(MerchantUtils.getMerchant().getId(), name) == null) {
			return "true";
		}
		return "false";
	}
	
	@RequiresPermissions("ivm:product:edit")
	@RequestMapping(value = "updateOpenState")
	public String updateOpenState(String id, String openState, RedirectAttributes redirectAttributes) {
		Product product = productService.get(id);
		if (product!=null && StringUtils.isNotBlank(product.getId())) {
			product.setOpenState(openState);
			productService.save(product);
		}
		addMessage(redirectAttributes, "商品信息"+(openState.equals("1")?"上架":"待售")+"成功");
		return "redirect:"+Global.getAdminPath()+"/ivm/product";
	}
	
	/**
	 * 批量修改单位排序
	 */
	@RequiresPermissions("ivm:product:edit")
	@RequestMapping(value = "updateSort")
	public String updateSort(String[] ids, Integer[] sorts, RedirectAttributes redirectAttributes) {
		if(Global.isDemoMode()){
			addMessage(redirectAttributes, "演示模式，不允许操作！");
			return "redirect:"+Global.getAdminPath()+"/ivm/product";
		}
    	int len = ids.length;
    	Product[] products = new Product[len];
    	for (int i = 0; i < len; i++) {
    		products[i] = productService.get(ids[i]);
    		products[i].setSort(i);
    		productService.save(products[i]);
    	}
    	addMessage(redirectAttributes, "保存商品排序成功!");
		return "redirect:"+Global.getAdminPath()+"/ivm/product";
	}
	
	@RequestMapping(value = "classifyChildList")
	public @ResponseBody Object getProductTwoClassifyList(String parentId){
		List<ProductClassify> list = ProductUtils.getClassifyTwoList(parentId);
		if (list!=null && list.size() > 0) {
			JSONArray jArray = new JSONArray();
			for (ProductClassify bean : list) {
				JSONObject data = new JSONObject();
				data.put("id", bean.getId());
				data.put("name", bean.getName());
				jArray.add(data);
			}
			return jArray;
		}
		return new JSONArray();
	}
	
	/**
	 * 手机端向上滑动翻页接口
	 * @param product
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "list/next")
	public @ResponseBody Object listNext(Product product, HttpServletRequest request, HttpServletResponse response, Model model) {
        Page<Product> page = productService.find(new Page<Product>(request, response), product, "", "", false); 
        return page;
	}
	
	/**
	 * web端，鼠标向下滑动加载更多
	 * @param product
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "list/more")
	public @ResponseBody Object listMode(Product product, 
			@RequestParam(value="searchParam", required=false, defaultValue="") String searchParam,   
			@RequestParam(value="oneClassify", required=false, defaultValue="") String oneClassify,   //一级分类
			@RequestParam(value="twoClassify", required=false, defaultValue="") String twoClassify,   //二级分类
			@RequestParam(value="sortName", required=false, defaultValue="") String sortName,   //排序字段
			@RequestParam(value="orderBy", required=false, defaultValue="") String orderBy,   //排序方式
			HttpServletRequest request, HttpServletResponse response, Model model) {
		if(StringUtils.isNotBlank(searchParam)){
			try {
				searchParam = java.net.URLDecoder.decode(searchParam,"UTF-8");
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		}
		if (StringUtils.isNotBlank(oneClassify)) {
			product.setClassify(new ProductClassify(oneClassify));
			List<String> classifyIdList = Lists.newArrayList();
			if(StringUtils.isNotBlank(twoClassify)){
				classifyIdList.add(twoClassify);
			}
			product.setClassifyIdList(classifyIdList);
		}else{
			List<String> classifyIdList = Lists.newArrayList();
			if(StringUtils.isNotBlank(twoClassify)){
				classifyIdList.add(twoClassify);
			}
			product.setClassifyIdList(classifyIdList);
		}
		String sort = sortName+"#"+orderBy;
		if(StringUtils.isBlank(sortName)){
			sort = "sort#asc";
		}
        Page<Product> page = productService.find(new Page<Product>(request, response), product, searchParam, sort, true); 
        System.out.println("------------------------"+page.getPageNo());
        return page;
	}
	
	/**
	 * 打开销售状态面板
	 */
	@RequestMapping(value = "showOpenState")
	public String showOpenState(
			String id,
			HttpServletRequest request, HttpServletResponse response, Model model) {
		Product product = productService.get(id);
		model.addAttribute("product", product);
		return "modules/ivm/pro/editOpenState";
	}
	
	/**
	 * 打开支付方式面板
	 */
	@RequestMapping(value = "showPayState")
	public String showPayState(
			String id,
			HttpServletRequest request, HttpServletResponse response, Model model) {
		Product product = productService.get(id);
		model.addAttribute("product", product);
		return "modules/ivm/pro/editPayState";
	}
	
	/**
	 * 打开摸价周期面板
	 */
	@RequestMapping(value = "showPriceCycleSet")
	public String showPriceCycleSet(
			String id,
			HttpServletRequest request, HttpServletResponse response, Model model) {
		Product product = productService.get(id);
		model.addAttribute("product", product);
		return "modules/ivm/pro/editPriceCycleSet";
	}
	
	/**
	 * 打开市场价面板
	 */
	@RequestMapping(value = "showMarketPrice")
	public String showMarketPrice(
			ProductMarketDetail productMarketDetail,
			HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<ProductMarketDetail> page = productMarketDetailService.find(new Page<ProductMarketDetail>(request, response), productMarketDetail); 
		model.addAttribute("page", page);
		Product product = productService.get(productMarketDetail.getProduct().getId());
		model.addAttribute("product", product);
		model.addAttribute("priceType", productMarketDetail.getType());
		return "modules/ivm/pro/productMarketDetailList";
	}
	
	/**
	 * 打开商品详情面板
	 */
	@RequestMapping(value = "showProductDetail")
	public String showProductDetail(
			String id,
			HttpServletRequest request, HttpServletResponse response, Model model) {
		Product product = productService.get(id);
		model.addAttribute("product", product);
		model.addAttribute("type", "");
		return "modules/ivm/pro/productDetail";
	}
	
	/**
	 * 打开销售市场面板
	 */
	@RequestMapping(value = "showProductSupplier")
	public String showProductSupplier(
			String id,
			HttpServletRequest request, HttpServletResponse response, Model model) {
		Product product = productService.get(id);
		model.addAttribute("product", product);
		model.addAttribute("supplierList", product.getSupplierList());
		return "modules/ivm/pro/productSupplierList";
	}
	
	/**
	 * 修改销售状态
	 */
	@RequestMapping(value = "changeOpenState")
	public String changeOpenState(
			Product product,
			HttpServletRequest request, HttpServletResponse response, Model model) {
		model.addAttribute("product", product);
		productService.save(product);
		model.addAttribute("type", "success");
		return "modules/ivm/pro/editOpenState";
	}
	
	/**
	 * 修改付款方式
	 */
	@RequestMapping(value = "changePayState")
	public String changePayState(
			Product product,
			HttpServletRequest request, HttpServletResponse response, Model model) {
		model.addAttribute("product", product);
		productService.save(product);
		model.addAttribute("type", "success");
		return "modules/ivm/pro/editPayState";
	}
	
	/**
	 * 修改摸价周期
	 */
	@RequestMapping(value = "changePriceCycle")
	public String changePriceCycle(
			Product product,
			HttpServletRequest request, HttpServletResponse response, Model model) {
		model.addAttribute("product", product);
		productService.save(product);
		model.addAttribute("type", "success");
		return "modules/ivm/pro/editPriceCycleSet";
	}
	
	/**
	 * 修改商品价格：原价、现价、进价
	 */
	@RequestMapping(value = "changePrice")
	public String changePrice(
			Product product,
			@RequestParam(value="type", required=false, defaultValue="1") int type,
			HttpServletRequest request, HttpServletResponse response, Model model) {
		model.addAttribute("product", product);
		productService.save(product);
		//向市价格变动表插入一条更新记录
			ProductMarketDetail marketDetail = new ProductMarketDetail();
			marketDetail.setMerchant(super.merchant);
			marketDetail.setProduct(product);
		if(type == 1){
			marketDetail.setPrice(product.getOriginalPrice());
		}else if(type == 2){
			marketDetail.setPrice(product.getPrice());
		}else{
			marketDetail.setPrice(product.getTradePrice());
		}
		marketDetail.setType(type);
		productMarketDetailService.save(marketDetail);
		model.addAttribute("type", "success");
		model.addAttribute("priceType", type);
		return "modules/ivm/pro/productMarketDetailList";
	}
	
	/**
	 * 修改商品详情
	 */
	@RequestMapping(value = "saveProduct")
	public String deleteProduct(
			Product product,
			HttpServletRequest request, HttpServletResponse response, Model model) {
		//分类
		List<ProductClassify> classifyList = Lists.newArrayList();
		List<String> classifyIdList = product.getClassifyIdList();
		for (ProductClassify classify : productService.findAllClassify()){
			if (classifyIdList.contains(classify.getId())){
				classifyList.add(classify);
			}
		}
		product.setClassifyList(classifyList);
		//设置供应商
		List<Supplier> supplierList = Lists.newArrayList();
		List<String> supplierIdList = product.getSupplierIdList();
		for (Supplier supplier : ProductUtils.getSupplierList()){
			if (supplierIdList.contains(supplier.getId())){
				supplierList.add(supplier);
			}
		}
		product.setSupplierList(supplierList);
		if(product.getDelFlag().equals("1")){
			productService.delete(product.getId());
		}else{
			productService.save(product);
		}
		model.addAttribute("type", "success");
		return "modules/ivm/pro/productDetail";
	}
	
	/**
	 * 导出商品
	 */
	@RequestMapping(value = "export", method=RequestMethod.POST)
	public @ResponseBody Object exportFile(String[] productIds, 
			Product prod, 
			@RequestParam(value="searchParam", required=false, defaultValue="") String searchParam,   
			@RequestParam(value="oneClassify", required=false, defaultValue="") String oneClassify,   //一级分类
			@RequestParam(value="twoClassify", required=false, defaultValue="") String twoClassify,   //二级分类
			@RequestParam(value="sortName", required=false, defaultValue="") String sortName,   //排序字段
			@RequestParam(value="orderBy", required=false, defaultValue="") String orderBy,   //排序方式
			HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes) {
		String filePath = null;
		if(StringUtils.isNotBlank(searchParam)){
			try {
				searchParam = java.net.URLDecoder.decode(searchParam,"UTF-8");
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		}
		if (StringUtils.isNotBlank(oneClassify)) {
			prod.setClassify(new ProductClassify(oneClassify));
			List<String> classifyIdList = Lists.newArrayList();
			if(StringUtils.isNotBlank(twoClassify)){
				classifyIdList.add(twoClassify);
			}
			prod.setClassifyIdList(classifyIdList);
		}else{
			List<String> classifyIdList = Lists.newArrayList();
			if(StringUtils.isNotBlank(twoClassify)){
				classifyIdList.add(twoClassify);
			}
			prod.setClassifyIdList(classifyIdList);
		}
		try {
			List<Product> productList = Lists.newArrayList();
			if(productIds == null){//全部导出
				String sort = sortName+"#"+orderBy;
				if(StringUtils.isBlank(sortName)){
					sort = "sort#asc";
				}
				Page<Product> page = productService.find(new Page<Product>(request, response), prod, searchParam, sort, false); 
				productList = page.getList();
			}else {
				productList = productService.findSelects(productIds);
			}
		    //获取文件保存路径
		    filePath=Global.getConfig("upload.path");
		    String childDir = "template/";
		    filePath += (childDir +"Product_List.xls");
			File excelFile = new File(filePath);
			excelFile.createNewFile();
			//构建数据
			//生成excel数据列的标题
			String columnValue = "所属分类,商品编号,商品名称,副标题,销售状态,原价,现价,销售单位,商品规格,采购说明,起购数量,限购数量,是否支持到付,购物车有效时间,进价,默认供应商,库存状态";
			String[] columnValues = columnValue.split(",");
			List<String> columns = new ArrayList<String>();
			for (int i=0; i<columnValues.length; i++) {
				columns.add(columnValues[i]);
			}
			//生成excel单元格数据
			//生成excel单元格数据-第1行的数据
			Map<String, List<String>> data = new LinkedHashMap<String, List<String>>();
			List<String> rowData = new ArrayList<String>();
			for(Product product: productList){
				rowData = new ArrayList<String>();
				List<ProductClassify> classifyList = product.getClassifyList();//商品所属分类
				String classifyStr = "";
				if(classifyList != null && classifyList.size()>0){
					for(ProductClassify classify:classifyList){
						classifyStr = ","+classify.getName();
					}
					classifyStr = classifyStr.substring(1);
				}
				rowData.add(classifyStr);//所属分类
				rowData.add(product.getCode()+"");
				rowData.add(product.getName());
				rowData.add(product.getAssisTitle());
				if(product.getOpenState().equals("1")){
					rowData.add("上架");
				}else{
					rowData.add("待售");
				}
				rowData.add(product.getOriginalPrice()+"");
				rowData.add(product.getPrice()+"");
				if(product.getProductUnit() != null){
					rowData.add(product.getProductUnit().getName());
				}else{
					rowData.add("");
				}
				if(product.getSpecUnit() != null){
					rowData.add(product.getSpecNum()+product.getSpecUnit().getName());
				}else{
					rowData.add(product.getSpecNum()+"");
				}
				rowData.add(product.getPurchaseDesc());
				rowData.add(product.getStartSaleNum()+"");
				rowData.add(product.getPurchaseNum()+"");
				if(product.getToPay().equals("1")){
					rowData.add("是");
				}else{
					rowData.add("否");
				}
				rowData.add(product.getEffectiveTime());
				rowData.add(product.getTradePrice()+"");
				//默认供应商
				Supplier supplier = product.getDefaultSupplier();
				String supplierStr = "";
				if(supplier != null){
					supplierStr = supplier.getName();
				}
				rowData.add(supplierStr);
				if(product.getStockState().equals("1")){
					rowData.add("真实");
				}else{
					rowData.add("虚拟");
				}
				data.put(product.getId()+"", rowData);
			}
			//调用ExcelManager对象write数据
			excelManager.writeExcel(excelFile, "商品", columns, data);
			//返回文件名
			//response.getWriter().print(fileURL);
		} catch (Exception e) {
			e.printStackTrace();
			return getStatusBean(400, "商品导出失败");
		}
		//return "redirect:"+Global.getAdminPath()+"/ivm/order/?repage";
		return getStatusBean(200, filePath);
	}
}
